<template>
  <!-- custom-class="workflow"  class="workflow" -->
  <el-dialog top="8vh" :visible.sync="isVisiable" v-if="isVisiable" width="90%"
             :close-on-click-modal="false" append-to-body @close="guanbi">
    <el-container>
      <div ref="mydiv"
           :style="'margin-left:-10px;pointer-events: none; background-color:transparent;position:absolute;width:100%;height:' + (clientHeight - 180) + 'px;'"></div>
      <el-tabs type="card" v-model="activeName" class="tabBox" style="height: 70vh; margin-bottom: 10px;">
        <el-tab-pane label="业务信息">

          <el-container>
            <el-main class="scorll-box" style="height: 60vh;">
              <div>
                <yjhthtcj ref="yjhthtcjs" v-if="type==='JJ_FP'"></yjhthtcj>
                <yjhthtcjff ref="yjhthtcjff" v-else></yjhthtcjff>
              </div>
            </el-main>
          </el-container>

        </el-tab-pane>
      </el-tabs>
      <el-footer style="text-align:center; margin-top: 20px; z-index: 100;" class="dialog-footer">
        <!-- <el-button @click="backExecute" style="margin-right:10px;" type="warning" :disabled="isDisable">退回</el-button> -->
        <div v-if="fromName=='待办'">
          <span v-for="item in flagList" :key="item">
                  <el-button type="primary" v-if="item=='通过'" style="margin:0 10px;"
                            @click="submit(item)">{{ item }}</el-button>
                  <el-button type="warning" v-if="item=='驳回'" @click="submit(item)">{{ item }}</el-button>
            <!--                <el-button type="primary" v-if="item=='提交'">{{ item }}</el-button>-->
          </span>
          <el-button type="primary" style="margin-left:10px;" v-if="flagText=='审核'" @click="guanbi">列表模式</el-button>
        </div>
      </el-footer>
      <el-col :span="24" v-if="fromName=='待办'">
        <el-input v-model="examination" placeholder="审批意见" :rows="2" type="textarea"></el-input>
      </el-col>
    </el-container>
  </el-dialog>
</template>

<script>
import {Message} from "element-ui";
import {mapGetters, mapState} from "vuex";
import mainform from "./main";
import yjhthtcj from "@/views/jiangjin/jiangjinfpjjfpdjb/view";
import yjhthtcjff from "@/views/jiangjin/jiangjinfpjjfpdjb/viewFf1";
import {
  getJJTaskById,
  submitJJTask
} from "@/api/workflow/wfywmain";

export default {
  components: {
    mainform,
    yjhthtcj,
    yjhthtcjff
  },
  name: "jiangjinWork",
  data() {
    return {
      isVisiable: false,
      isBackVisiable: false,
      clientHeight: 600,
      activeName: 0,
      taskId: "",
      processInstanceId: '',
      flagList: [],
      examination: "",
      fromName: "",
      fpId: "",
      type: "",
      flagText:""
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    ...mapState({
      userInfo: (state) => state.user.userInfo,
    }),
    newBmid() {
      return this.fqRyInfo.bmId;
    },
    dianzan() {
      return this.supportcount.userzj == 0 ? "color:#424242" : "color:#0961bc";
    },
  },
  mounted() {
    this.userId = this.userInfo.userId;
  },
  methods: {
    // 关闭
    guanbi() {
      this.isVisiable = false;
      this.$emit("jiangChild", '关闭')
    },
    open(fpId, taskId, processInstanceId, type, text,flagText) {
      this.examination = ''
      this.taskId = taskId
      this.fromName = text
      this.type = type
      this.flagText=flagText
      this.processInstanceId = processInstanceId
      this.fpId = fpId
      this.isVisiable = true
      if (taskId) {
        this.getBtn(this.taskId,this.processInstanceId)
      }

      this.$nextTick(() => {
        if (type === 'JJ_FP') {
          this.$refs.yjhthtcjs.init(fpId)
        }else {
          this.$refs.yjhthtcjff.init1(fpId)
        }
      })
    },
    //获取按钮
    getBtn(taskId) {
      //原来的代码中通过getJJTaskById方法返回flagList，可能是想通过审批状态控制是否允许用户，但实际根本没有返回，暂时先固定返回 '通过','驳回'
      //this.flagList=['通过','驳回'];
      getJJTaskById(taskId).then(res => {
        this.flagList = res.data.data.flagList
      })
    },
    //提交审批意见数据
    submit(item) {
      var params = {
        fpId: this.fpId,
        taskId: this.taskId,
        processId:this.processInstanceId,
        taskFlag: item,
        type: this.type,
        comment: this.examination
      }
      submitJJTask(params).then(res => {
        console.log("提交审批:" + JSON.stringify(res))
        if (res.data.data) {
          this.$message.success('提交成功!')
          this.isVisiable = false
          this.$emit("jiangChild", '成功')
        } else {
          this.$message.success('提交失败!')
          this.isVisiable = false
          this.$emit("jiangChild", '失败')
        }
      })
    },
  }
}
</script>

<style>

</style>
